package com.dog.modules.demo.web;

import com.alibaba.fastjson.JSON;
import com.dog.framework.core.enums.ResponseCodeEnum;
import com.dog.framework.core.exception.DemoException;
import com.dog.framework.core.utils.I18nUtils;
import com.dog.modules.upms.dto.request.UserReqDto;
import com.dog.modules.upms.dto.response.UserRespDto;
import com.dog.modules.upms.feign.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {


    @Autowired
    private UserClient userClient;



    @GetMapping("/log")
    public String log(){
        log.info("===============hello world===========");
        String code = "user.jcaptcha.error";
        String message = I18nUtils.message(code);
        if(true){
          //  throw  new DemoException("user.not.exists",new Object[]{"hello"});
            throw new DemoException(ResponseCodeEnum.MAIL_CONTENT_NOT_EMPTY);
        }
        return message;
    }



    @PostMapping(value = "/user/add")
    UserRespDto add(@RequestBody @Valid UserReqDto userReqDto){
        log.info("远程调用服务upms-biz-service，请求参数{}", JSON.toJSONString(userReqDto));
        UserRespDto userRespDto  =  userClient.add(userReqDto);
        log.info("远程调用服务upms-biz-service，返回结果{}",JSON.toJSONString(userRespDto));
        userRespDto.setMessage("服务system-biz-service返回结果");
        return  userRespDto;
    }


}
